function [finalSequence, passingIdx]=examineCurve(totalSequence, d, delta_min, tour, sites, triangles, triangleGrid, propertyFile)

numCurves=(size(totalSequence,2)-1)/2;
numTours=size(tour,1);

passingIdx=zeros(1,numTours);

theLength=zeros(1,numCurves);
theCurvature=zeros(1,numCurves);
theSafety=zeros(1,numCurves);

tourIdx=1;
for i=1:numCurves
    %current curve of interst
    P=totalSequence(:,(2*i-1));
    Q=totalSequence(:,(2*i));
    R=totalSequence(:,(2*i+1));
    
    %calculate three criteria...
    theLength(i)=findLength(P,Q,R);
    theCurvature(i)=findCurvature(P,Q,R);
    theSafety(i)=findSafety(P,Q,R,sites,triangles, triangleGrid);
    sites(:,3)=sites(:,3)+6;
    violation(P,Q,R,sites,triangles, triangleGrid);
    sites(:,3)=sites(:,3)-6;
    
    %verify pass sights
    if passSight(P,tour(tourIdx,:)',d)
        passingIdx(tourIdx)=(2*i-1);
        tourIdx=tourIdx+1;
    end
    
    %verify C1 continuity
    if i~=1
        prev=totalSequence(:,(2*i-2));
        t=(prev-P)./(P-Q);
        t=t-t(1);
        if norm(t)>0.00001
            disp('C1 continuity not hold!');
        end
    end
end


if passSight(R,tour(tourIdx,:)',d)
    passingIdx(tourIdx)=2*numCurves+1;
    if tourIdx==numTours
        disp('all sights are passed!');
    end
end


theCurvature=max(theCurvature);
theSafety=min(theSafety)+delta_min;
    finalSequence=totalSequence;
%[finalSequence, theLength]=optimizeCurve(totalSequence, theCurvature, theSafety, theLength);
theLength=sum(theLength);
writeProperty(propertyFile, numCurves, theCurvature, theSafety, theLength);

end



function writeProperty(propertyFile, N, theCurvature, theSafety, theLength)
N, theCurvature, theSafety, theLength
fid=fopen(propertyFile,'w');
fprintf(fid, 'total %d curves\n',N);
fprintf(fid, 'curvature=%f\n',theCurvature);
fprintf(fid, 'safety=%f\n',theSafety);
fprintf(fid, 'length=%f\n',theLength);
fclose(fid);
end